<?php
require APPPATH.'libraries/ApiController.php';
class capthcha extends ApiController {
	public function __construct()
	{
		parent::__construct();
	}
	
	
	public function generate(){
		// 创建画布
		$width = 100;
		$height = 30;
		$image = imagecreate($width, $height);
		
		// 设置背景色和文字颜色
		$bgColor = imagecolorallocate($image, 255, 255, 255);
		$textColor = imagecolorallocate($image, 0, 0, 0);
		
		// 生成随机验证码
		$code = substr(str_shuffle('0123456789'), 0, 4);
		
 
		// 将验证码写入图片
		imagestring($image, 5, 30, 5,$code,$textColor);
		
		// 输出图片
		header('Content-Type: image/png');
		imagepng($image);
		
		// 销毁资源
		imagedestroy($image);
	}
	
	
}